import time
import numpy as np
# import requests
from PIL import ImageGrab
from playsound import playsound  # 用于播放本地音频文件

# 指定要监测的区域
monitor_area = (1589, 835, 1604, 850)  # (左上角x坐标, 左上角y坐标, 右下角x坐标, 右下角y坐标)
# 初始截图
last_screen = np.array(ImageGrab.grab(monitor_area))
# 指定HTTP请求的URL
# url = "改成你的POST通知的URL，例如企业微信、Bark、钉钉、发送邮件等"
# 音频文件路径
sound_file = 'alert.mp3'
# 时间间隔，单位为秒
interval = 10

time.sleep(interval)

while True:
    # 捕获当前屏幕截图
    current_screen = np.array(ImageGrab.grab(monitor_area))

    # 将上次截图和当前截图进行比较
    difference = np.sum(np.abs(current_screen - last_screen))

    # 如果界面没变化
    if difference == 0:
        print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + "界面没有变化")
        # 发出提示
        if sound_file:
            playsound(sound_file)  # 播放本地音频文件
        # # 发送HTTP POST请求
        # data = {"timestamp": time.time(), "difference": difference}
        # response = requests.post(url, data=data)
        # print(response.text)

    # 更新上次截图
    last_screen = current_screen

    # 休眠一段时间，然后继续循环
    time.sleep(interval)
